package com.qcrud.core;

import java.io.Closeable;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class StatementContext implements Closeable {
    private PreparedStatement preparedStatement;
    private Connection connection;
    private Binding binding = new Binding();

    public StatementContext(ConnectionFactory connectionFactory) {
        this.connection = connectionFactory.openConnection();
    }

    @Override
    public void close() throws IOException {

    }

    public Connection getConnection() {
        return this.connection;
    }

    public SqlStatement createSqlStatement(String sql) throws SQLException {
        preparedStatement = connection.prepareStatement(sql);
        return new SqlStatement(this, sql, preparedStatement);
    }

    public Binding getBinding() {
        return this.binding;
    }
}
